import os

import facade
from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curPath, "db.ini")
topPath = BaseDir.get_upper_dir(curPath, -2)
sPath = BaseDir.get_new_path(topPath, "download", "bookan_shanxia", "download", "cover")
sPath = r"\\192.168.30.177\样例数据\bookanjournal\bookanjournal_cover_all"
BaseDir.create_dir(sPath)


class MapCover(object):
    def __init__(self):
        self.logger = facade.get_streamlogger()
        self.mysqlutil = facade.MysqlUtiles(configfile, "db", logger=self.logger)

    def map_cover(self):
        provider = 'bookanjournal'
        filePath = provider + '_cover.txt'
        filePath = BaseDir.get_new_path(r"\\192.168.30.177\样例数据\bookanjournal",filePath)
        nCount = 0
        with open(filePath, mode='w', encoding='utf-8') as f:
            for path, dirNames, fileNames in os.walk(sPath):
                for fileName in fileNames:
                    # 分离文件名与扩展名 返回文件名和扩展名
                    journal = os.path.splitext(fileName)[0]
                    line = provider + '@' + journal + '★/smartlib/' + provider + '/' + fileName + '\n'
                    f.write(line)
                    nCount += 1
        print('nCount:' + str(nCount))


def main():
    down = MapCover()
    down.map_cover()


if __name__ == "__main__":
    main()
